﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace TheVoiceOfSnake
{
    class MainForm : Form
    {
        private MainMenu MainMenu;
        private MenuItem ExtractParams;
        private string DisplayedText;
        private TextBox TextBox;
        Graphics surface;

        public MainForm()
        {
            this.Height = 600;
            this.Width = 600;
            this.Name = "The Voice of Snake";
            this.Text = "The Voice of Snake";
            this.CenterToScreen();
            surface = this.CreateGraphics();
            DisplayedText = "";
            ExtractParameters();

            TextBox = new TextBox();
            TextBox.Multiline = true;
            TextBox.Width = 600;
            TextBox.Height = 200;
            TextBox.Visible = true;
            TextBox.AppendText(DisplayedText);
            
            this.Controls.Add(TextBox);
            this.Visible = true;
            this.AutoScroll = true;

            MainMenu = new MainMenu();
            ExtractParams = MainMenu.MenuItems.Add("Ekstrakcja parametrów");
            this.Menu = MainMenu;

            /* obsługa zdarzeń generowanych przez menu */
            EventHandler extractEH = new EventHandler(onClickExtract);
            ExtractParams.Click += extractEH;

            /* stworzenie zdarzenia odpowiedzialnego za przerysowywanie ekranu */
            PaintEventHandler paintEH = new PaintEventHandler(onPaint);
            this.Paint += paintEH;
        }

        public void onPaint(object sender, PaintEventArgs e)
        {
        }

        public void onClickExtract(object sender, EventArgs args)
        {
            ExtractParameters();
            TextBox.Clear();
            TextBox.AppendText(DisplayedText);
            TextBox.Height += 172;
            onPaint(this, new PaintEventArgs(this.surface, this.ClientRectangle));
        }

        private void ExtractParameters() 
        {
            SpeechRecognizer sr = new SpeechRecognizer();
            InputValue inp = new InputValue();
            DisplayedText += sr.ExtractParameters(inp.Get());
        }
    }
}
